<template>
    <div class="pt44">
        <div v-if="channelNo1" class="paster">
            <div class="fl"><img v-bind:src="this.$store.state.imagesUrl + 'xiaotongshandai_icon.png'"></div>
            <div class="explain">
                <div class="title">
                    小通帮你借
                </div>
                <ul>
                    <li>
                        <img v-bind:src="this.$store.state.imagesUrl + 'lilvdi_icon2.png'"><span>随借随还</span>
                    </li>
                    <li>
                        <img v-bind:src="this.$store.state.imagesUrl + 'suijiesuihuan_icon2.png'"><span>利率低</span>
                    </li>
                    <li>
                        <img v-bind:src="this.$store.state.imagesUrl + 'zhichi25tiande duanqichaijie_icon2.png'"><span>支持1-25天的短期拆借</span>
                    </li>
                </ul>
                <router-link to="/interest" class="weui-btn weui-btn_mini weui-btn_primary">我要申请</router-link>
            </div>
        </div>
        <div v-if="channelNo2" class="paster">
            <div class="fl"><img v-bind:src="this.$store.state.imagesUrl + 'zhangqiguanli_icon.png'"></div>
            <div class="explain">
                <div class="title">
                    小通帮你延
                </div>
                <ul>
                    <li>
                        <img v-bind:src="this.$store.state.imagesUrl + '81tian_icon.png'"><span>最长可达81天账期</span>
                    </li>
                    <li>
                        <img v-bind:src="this.$store.state.imagesUrl + 'lilvdi_icon.png'"><span>利率低</span>
                    </li>
                    <li>
                        <img v-bind:src="this.$store.state.imagesUrl + 'edugao_icon.png'"><span>额度高</span>
                    </li>
                </ul>
                <router-link to="/accountIntest" class="weui-btn weui-btn_mini weui-btn_primary">我要申请</router-link>
            </div>
        </div>
        <div class="page__bd page__bd_spacing">
            <router-link to="/loanRecord" class="weui-btn weui-btn_plain-primary">交易查询</router-link >
        </div>
    </div>
</template>

<script>
import { getDateStrFormate1,getDateStrFormate } from "../components/common.js";

export default  {
    name: 'Home',  // 组件名称
    data () {  // 数据
        return {
          msg: 'Home',
          channelNo1:false,
          channelNo2:false
        }
    },
    props:['merId'],
    methods:{ // 自定义方法，可对data进行处理
        getMerName(){  // 取商户名称 和开通的产品
            var _this = this;
            $.post(XtsdOrderServlet, {
                merNo:this.$store.state.tlMerId,
                servlet_type:"query_mer_prdt"
            }, function (merDate) {
                console.dir(merDate);
                if(merDate.xtsd_PrdtMulRate_response && merDate.xtsd_PrdtMulRate_response.resXtsdOrderInfos_arrays && merDate.xtsd_PrdtMulRate_response.resXtsdOrderInfos_arrays.resXtsdOrderInfos && merDate.xtsd_PrdtMulRate_response.resXtsdOrderInfos_arrays.resXtsdOrderInfos.length){
                    var merInfos = merDate.xtsd_PrdtMulRate_response.resXtsdOrderInfos_arrays.resXtsdOrderInfos;
                    document.title = merInfos[0].corpAbbr;
                    for(var i=0,l=merInfos.length;i<l;i++){
                        if(merInfos[i].channelNo == "01"){
                            _this.channelNo1 = true;
                        }else if(merInfos[i].channelNo == "02"){
                            _this.channelNo2 = true;
                        }
                    }
                    if(!_this.channelNo1 && !_this.channelNo2){
                        _this.$store.state.errorMsg = "该商户未开通任何产品";
                    }
                }
            });
        },
        clearInterstData(){ // 清空帮你借数据
            this.$store.state.loanApplyMoney = "";
            this.$store.state.maximumRepay = "0.00";
        },
        clearAccountData(){ // 清空帐期数据
            this.$store.state.accountLoanAmount = "";
            this.$store.state.statementDate = "";
            this.$store.state.accountreMonthpaymentDate = "";
            this.$store.state.accountRepaymentDate = "";
            this.$store.state.loanDays = "";
            this.$store.state.accountLoanAmount = "";
            this.$store.state.accountServiceCharge = "";
            this.$store.state.accountRepaymentAmount = "";
            this.$store.state.dailyInterest = ""
        }

    },
    beforeMount:function  () {
        var _this = this;
        this.$store.state.tlMerId = this.merId;
        this.$store.state.openid = encodeURIComponent(this.$route.query.openid);
        this.$store.state.headerTitle = "";
        this.$store.state.nowDate = new Date();
        $.post(XtsdOrderServlet,{"servlet_type":"query_today"},function(dmsg) {
            if(dmsg.today_response && dmsg.today_response.today){
                var nowDateStr = getDateStrFormate1(dmsg.today_response.today,"date") + " 00:00:01";
                _this.$store.state.nowDate = new Date(nowDateStr.replace(/-/g, "/"));
                _this.getMerName();
            }
        });
 //       this.$store.commit('setNowDate');
    },
    mounted(){
        this.$store.state.showBack = false;
    },
    beforeRouteLeave(to, from, next){ // 离开时清楚申请金额 利息数据
        this.clearInterstData();
        this.clearAccountData();
        this.$store.state.showBack = true;
        if(from.name == "Result"){
            if(this.$store.state.channelNo == "01"){
                location.hash = "#/loanRecord";
            }else{
                location.hash = "#/accountRecord";
            }
        }else{
           next();
        }

    }


}
</script>

<style lang='scss' scoped>
.paster{
    background: #fff;
    margin: 10px 15px;
    .fl{
        img{
            width: 105px;
            height:190px;
        }
    }
}
.explain{
    padding: 10px 0 0 124px;
    li{
        font-size: 14px;
    }
    .title{
        color: #2792e4;
        margin-bottom: 10px;
        font-size: 20px;
    }
    li{
        line-height: 36px;
    }
    img{
        height: 20px;
        vertical-align: sub;
        margin-right: 6px;
    }
    .weui-btn_mini{
        width: 150px;
    }
}
.page__bd_spacing{
    margin-top: 15px;
    padding: 0 15px;
}
</style>
